package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ActivityController
 * Package: com.qk.controller
 * Description:
 *
 * @Author zt
 * @Create 2025/7/30 20:58
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    /*
    1.活动列表分页查询
     */
    @GetMapping
    public Result listActivities(ActivityDto activityDto) {
        log.info("活动列表分页查询：{}",activityDto);
        //PageResult中包含分页的基本信息
        PageResult<Activity> pageResult =activityService.listActivities(activityDto);
        return Result.success(pageResult);
    }

    /*
    2.删除活动
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除活动：{}", id);
        activityService.delete(id);
        return Result.success();
    }

    /*
    3.添加活动
     */
    @PostMapping
    public Result add(@RequestBody Activity activity) {
        log.info("添加活动：{}", activity);
        activityService.add(activity);
        return Result.success();
    }

    /*
    4.根据ID查询
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("查询活动：{}", id);
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    /*
    5.修改活动
     */
    @PutMapping
    public Result update(@RequestBody Activity activity) {
        log.info("修改活动：{}", activity);
        activityService.update(activity);
        return Result.success();
    }

    /*
    6.查询指定的活动类型（有多条，集合接收）
     */
    @GetMapping("/type/{type}")
    public Result listByType(@PathVariable Integer type) {
        log.info("查询指定类型：{}", type);
        List<Activity> activities = activityService.listByType(type);
        return Result.success(activities);
    }

    /*
    7.查询所有活动
     */
    @GetMapping("/list")
    public Result list() {
        log.info("查询所有活动");
        List<Activity> list = activityService.list();
        return Result.success(list);
    }

}
